﻿using System;
using System.ComponentModel;
using System.Windows.Input;

namespace Gma.UserActivityMonitor
{
    /// <summary>
    /// This component monitors all mouse activities globally (also outside of the application) 
    /// and provides appropriate events.
    /// </summary>
    public class GlobalEventProvider : Component
    {
        /// <summary>
        /// This component raises events. The value is always true.
        /// </summary>
        protected override bool CanRaiseEvents
        {
            get
            {
                return true;
            }
        }

        private event MouseEventHandler MouseMoveEvent;

        /// <summary>
        /// Occurs when the mouse pointer is moved. 
        /// </summary>
        public event MouseEventHandler MouseMove
        {
            add
            {
                if (MouseMoveEvent == null)
                    HookManager.MouseMove += HookManager_MouseMove;
                MouseMoveEvent += value;
            }

            remove
            {
                MouseMoveEvent -= value;
                if (MouseMoveEvent == null)
                    HookManager.MouseMove -= HookManager_MouseMove;
            }
        }

        private void HookManager_MouseMove(object sender, MouseEventArgs e)
        {
            if (MouseMoveEvent != null)
                MouseMoveEvent.Invoke(this, e);
        }
    }
}